package com.jianyun.jyzs.widget;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupWindow;


import com.jianyun.jyzs.R;
import com.jianyun.jyzs.adapter.IntegratedAdapter;
import com.jianyun.jyzs.bean.IntegratedResult;
import com.jrmf360.rylib.common.util.ScreenUtil;

import java.util.List;

/**
 * Created by liml on 17/5/23.
 */

public class IntegratedPopu extends PopupWindow{
    private List<IntegratedResult> list;

    private final View conentView;

    public IntegratedPopu(Context context, List<IntegratedResult> strs, AdapterView.OnItemClickListener listener) {
        this.list = strs;
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        conentView = inflater.inflate(R.layout.popu_integrated, null);
        setContentView(conentView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ScreenUtil.getScreenWidth(context)/3);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(000000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);

        // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AnimationPreview);
        ListView listview = (ListView) conentView.findViewById(R.id.lv_integratd);
        listview.setOnItemClickListener(listener);
        IntegratedAdapter adapter = new IntegratedAdapter(list, context);
        listview.setAdapter(adapter);

    }
    public void showPopupWindow(View parent) {
        if (!this.isShowing()) {
            // 以下拉方式显示popupwindow
            this.showAsDropDown(parent, 0, 0);
        } else {
            this.dismiss();
        }
    }
}

